const Activity = require("../models/activity");
const { Op } = require("sequelize");

//获取活动数据
exports.list = async function( page,size,todayDate,city){
    page = Number(page);
    size = Number(size);
    city = city=='城市'?'':city;
    return Activity.findAndCountAll({
        where:{
            endJoin1:{
                [Op.gte]: todayDate
            },
            place:{
                [Op.like]: `%${city}%`
            }
        },
        attributes:['id','title','img','place','endJoin1','endJoin2'],
        limit: size,
        offset: (page - 1) * size,
        order: [['endJoin1', 'ASC']],
    });
}

//获取即将报名结束的三个活动
exports.quickEnd = async function(todayDate){
    return Activity.findAll({
        where:{
            endJoin1:{
                [Op.gte] : todayDate
            }
        },
        attributes:['id','title','img'],
        order: [['endJoin1', 'ASC']],
        limit:3
    })
}

//获取活动详情
exports.getDetail = async function(id){
    return Activity.findByPk(id,{
        attributes:{exclude:['createdAt','updatedAt','deletedAt']}
    });
}


